package com.schoolcloud.serve.controller;

import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.model.R;
import com.schoolcloud.serve.dto.GoodsCreateDTO;
import com.schoolcloud.serve.dto.SkuAndSaleAttributeAndPictureDTO;
import com.schoolcloud.serve.dto.SkuModifyDTO;
import com.schoolcloud.serve.entity.Sku;
import com.schoolcloud.serve.query.SkuQuery;
import com.schoolcloud.serve.service.SkuInteractionService;
import com.schoolcloud.serve.service.SkuService;
import com.schoolcloud.serve.vo.SkuItemDetailVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/serve/re-market/sku")
@RequiredArgsConstructor
public class SkuController {
    private final SkuService skuService;
    private final SkuInteractionService skuInteractionService;
    @GetMapping("/page")
    public R<PageDTO<Sku>> getSkuPage(SkuQuery skuQuery){
        PageDTO<Sku> page= skuService.getSkuPage(skuQuery);
        return R.ok(page);
    }
    @PostMapping
    public R createGoods(@RequestBody GoodsCreateDTO goodsSaveDTO){
        skuInteractionService.createGoods(goodsSaveDTO);
        return R.ok("创建成功");
    }
    @GetMapping("/{id}")
    public R<Sku> getById(@PathVariable Integer id){
        Sku sku=skuService.getById(id);
        return R.ok(sku);
    }
    @GetMapping("/modify-dto/{id}")
    public R<SkuModifyDTO> getSkuModifyDTO(@PathVariable String id){
        SkuModifyDTO dto= skuInteractionService.getSkuModifyDTO(id);
        return R.ok(dto);
    }
    @PutMapping
    public R modifySku(@RequestBody SkuModifyDTO dto){
        skuInteractionService.modifySku(dto);
        return R.ok("修改成功");
    }
    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable Integer id){
        skuService.removeById(id);
        return R.ok("删除成功");
    }
    @GetMapping("/detail/{id}")
    public R getSkuDetail(@PathVariable String id){
        SkuItemDetailVO vo=skuInteractionService.getSkuDetail(id);
        return R.ok(vo);
    }

}
